////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "TestSteeringAIHandler.hpp"

#include <SFML/Graphics.hpp>

#include <SmegAI/Steering/SteeringManager.hpp>
#include <SmegCore/Entity/EntityManager.hpp>

#include "TestSteeringAI.hpp"

#include "../../tinyxml2/tinyxml2.h"
#include "../../Canvas/SmegEditorCanvas.hpp"
#include "../../Form/SmegEditorFrame.h"
#include "../../Form/BaseEntityChooserDialog.h"

#include "../ObjectHandlerFactory.hpp"
#include "../ObjectHandlers.h"

////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////
TestSteeringAIHandler::TestSteeringAIHandler() :
    BaseEntityHandler(),
    m_SeekPursueEntityHandlerName( wxEmptyString ),
    m_pSeekPursueEntityHandler( NULL ),
    m_FleeEvadeEntityHandlerName( wxEmptyString ),
    m_pFleeEvadeEntityHandler( NULL )
{
    m_TmpPath.clear();
    m_TmpPath.push_back( sf::Vector2f( 500.0f, 0.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 250.0f, 250.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -30.0f, 400.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -600.0f, 150.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -400.0f, -100.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -150.0f, -400.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 100.0f, -500.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 300.0f, -300.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 650.0f, -200.0f ) );
}

////////////////////////////////////////////////////////////
/// Copy Constructor
////////////////////////////////////////////////////////////
TestSteeringAIHandler::TestSteeringAIHandler( const TestSteeringAIHandler& _Copy ) :
    BaseEntityHandler( _Copy ),
    m_SeekPursueEntityHandlerName( _Copy.m_SeekPursueEntityHandlerName ),
    m_pSeekPursueEntityHandler( NULL ),
    m_FleeEvadeEntityHandlerName( _Copy.m_FleeEvadeEntityHandlerName ),
    m_pFleeEvadeEntityHandler( NULL )
{
    m_TmpPath.clear();
    m_TmpPath.push_back( sf::Vector2f( 500.0f, 0.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 250.0f, 250.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -30.0f, 400.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -600.0f, 150.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -400.0f, -100.0f ) );
    m_TmpPath.push_back( sf::Vector2f( -150.0f, -400.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 100.0f, -500.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 300.0f, -300.0f ) );
    m_TmpPath.push_back( sf::Vector2f( 650.0f, -50.0f ) );
}

////////////////////////////////////////////////////////////
/// Constructor
////////////////////////////////////////////////////////////
TestSteeringAIHandler::~TestSteeringAIHandler()
{
}

////////////////////////////////////////////////////////////
    /// Does an render of things that doesn't usually happen
////////////////////////////////////////////////////////////
void TestSteeringAIHandler::Render() {
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    if ( pSteeringAI->IsFollowingPath() ) {
        float fNextStep = pSteeringAI->GetNextStepThreshold();

        // Display the path to follow
        sf::CircleShape circleStep( 5.0f ), 
            circleStepThreshold( fNextStep );

        circleStep.setOrigin( 5.0f, 5.0f );
        circleStepThreshold.setOrigin( fNextStep, fNextStep );
        circleStepThreshold.setFillColor( sf::Color::Transparent );
        circleStepThreshold.setOutlineColor( sf::Color::Cyan );
        circleStepThreshold.setOutlineThickness( 1.0f );

        sf::Vertex line[] = {
            sf::Vertex(),
            sf::Vertex()
        };

        // First point
        circleStep.setPosition( m_TmpPath[0] );
        circleStep.setFillColor( sf::Color::Blue );

        circleStepThreshold.setPosition( m_TmpPath[0] );
        
        m_pCanvas->draw( circleStep );
        m_pCanvas->draw( circleStepThreshold );

        line[0].position = m_TmpPath[0];
        line[1].position = m_TmpPath[1];
        m_pCanvas->draw( line, 2, sf::Lines );
    
        circleStep.setFillColor( sf::Color::White );
        for ( unsigned i = 1; i < m_TmpPath.size() - 1; ++i ) {
            circleStep.setPosition( m_TmpPath[i] );
            circleStepThreshold.setPosition( m_TmpPath[i] );

            m_pCanvas->draw( circleStep );
            m_pCanvas->draw( circleStepThreshold );

            line[0].position = m_TmpPath[i];
            line[1].position = m_TmpPath[ (i + 1) % m_TmpPath.size() ];
            m_pCanvas->draw( line, 2, sf::Lines );
        }

        // Last point
        circleStep.setPosition( m_TmpPath[m_TmpPath.size() - 1] );
        circleStep.setFillColor( sf::Color::Red );

        circleStepThreshold.setPosition( m_TmpPath[m_TmpPath.size() - 1] );

        m_pCanvas->draw( circleStep );
        m_pCanvas->draw( circleStepThreshold );

        line[0].position = m_TmpPath[m_TmpPath.size() - 1];
        line[1].position = m_TmpPath[0];
        m_pCanvas->draw( line, 2, sf::Lines );
    }
}

////////////////////////////////////////////////////////////
/// Init the handler and setup the properties
/// BaseEntityHandler::InitFromGrid need to be called AFTER the specialized class
////////////////////////////////////////////////////////////
bool TestSteeringAIHandler::InitFromGrid( wxPropertyGrid* _pPropertyGrid ) {
    m_pObject = new smeg::ai::TestSteeringAI( m_pCanvas );
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );

    // Max Steering Force
    wxPGProperty* pCurProp = _pPropertyGrid->GetProperty("Max Steering Force");
    pSteeringAI->GetSteeringManager()->SetMaxSteeringForce( pCurProp->GetValue().GetAny().As<float>() );

    // Seek Slowing Radius
    pCurProp = _pPropertyGrid->GetProperty("Seek Slowing Radius");
    pSteeringAI->SetSeekSlowingRadius( pCurProp->GetValue().GetAny().As<float>() );

    // Wander Distance
    pCurProp = _pPropertyGrid->GetProperty("Wander Distance");
    pSteeringAI->SetWanderDistance( pCurProp->GetValue().GetAny().As<float>() );

    // Wander Radius
    pCurProp = _pPropertyGrid->GetProperty("Wander Radius");
    pSteeringAI->SetWanderRadius( pCurProp->GetValue().GetAny().As<float>() );

    // Next Step Threshold
    pCurProp = _pPropertyGrid->GetProperty("Next Step Threshold");
    pSteeringAI->SetNextStepThreshold( pCurProp->GetValue().GetAny().As<float>() );

    return BaseEntityHandler::InitFromGrid( _pPropertyGrid );
}
    
////////////////////////////////////////////////////////////
/// Init the handler from an XMLElement
/// BaseEntityHandler::InitFromXML need to be called AFTER the specialized class
////////////////////////////////////////////////////////////
bool TestSteeringAIHandler::InitFromXML( tinyxml2::XMLElement* _pElement, const wxString& _ProjectPath ) {
    m_pObject = new smeg::ai::TestSteeringAI( m_pCanvas, m_pCanvas->GetViewCenter() );
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );

    if ( BaseEntityHandler::InitFromXML( _pElement, _ProjectPath ) ) {
        tinyxml2::XMLElement* pParamElem = _pElement->FirstChildElement( "Param" );

        while ( pParamElem ) {
            wxString paramName = pParamElem->Attribute( "name" );

            if ( "Seek Weight" == paramName ) {
                m_SeekPursueEntityHandlerName = pParamElem->Attribute("target");
                BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_SeekPursueEntityHandlerName ) );
                if ( pNewHandler ) {
                    m_pSeekPursueEntityHandler = pNewHandler;
                    pSteeringAI->SetSeekWeight( pParamElem->FloatAttribute( "weight" ), 
                        static_cast<smeg::core::BaseEntity*>( m_pSeekPursueEntityHandler->GetObject() ),
                        pParamElem->FloatAttribute( "slowing" ) );
                } else {
                    pSteeringAI->SetSeekWeight( pParamElem->FloatAttribute( "weight" ), NULL, pParamElem->FloatAttribute( "slowing" ) );
                }
            } else if ( "Pursue Weight" == paramName ) {
                m_SeekPursueEntityHandlerName = pParamElem->Attribute("target");
                BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_SeekPursueEntityHandlerName ) );
                if ( pNewHandler ) {
                    m_pSeekPursueEntityHandler = pNewHandler;
                    pSteeringAI->SetPursueWeight( pParamElem->FloatAttribute( "weight" ), 
                        static_cast<smeg::core::BaseEntity*>( m_pSeekPursueEntityHandler->GetObject() ) );
                } else {
                    pSteeringAI->SetPursueWeight( pParamElem->FloatAttribute( "weight" ) );
                }
            } else if ( "Flee Weight" == paramName ) {
                m_FleeEvadeEntityHandlerName = pParamElem->Attribute("target");
                BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_FleeEvadeEntityHandlerName ) );
                if ( pNewHandler ) {
                    m_pFleeEvadeEntityHandler = pNewHandler;
                    pSteeringAI->SetFleeWeight( pParamElem->FloatAttribute( "weight" ), 
                        static_cast<smeg::core::BaseEntity*>( m_pFleeEvadeEntityHandler->GetObject() ) );
                } else {
                    pSteeringAI->SetFleeWeight( pParamElem->FloatAttribute( "weight" ) );
                }
            } else if ( "Evade Weight" == paramName ) {
                m_FleeEvadeEntityHandlerName = pParamElem->Attribute("target");
                BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_FleeEvadeEntityHandlerName ) );
                if ( pNewHandler ) {
                    m_pFleeEvadeEntityHandler = pNewHandler;
                    pSteeringAI->SetEvadeWeight( pParamElem->FloatAttribute( "weight" ), 
                        static_cast<smeg::core::BaseEntity*>( m_pFleeEvadeEntityHandler->GetObject() ) );
                } else {
                    pSteeringAI->SetEvadeWeight( pParamElem->FloatAttribute( "weight" ) );
                }
            } else if ( "Wander Weight" == paramName ) {
                pSteeringAI->SetWanderWeight( pParamElem->FloatAttribute( "weight" ), 
                        pParamElem->FloatAttribute( "distance" ),
                        pParamElem->FloatAttribute( "radius" ) );
            } else if ( "Max Steering Force" == paramName ) {
                pSteeringAI->GetSteeringManager()->SetMaxSteeringForce( pParamElem->FloatAttribute( "value" ) );
            } else if ( "Next Step Threshold" == paramName ) {
                pSteeringAI->SetNextStepThreshold( pParamElem->FloatAttribute( "value" ) );
            }

            pParamElem = pParamElem->NextSiblingElement( "Param" );
        }
    }

    return true;
}
    
////////////////////////////////////////////////////////////
/// PostInit
///
////////////////////////////////////////////////////////////
void TestSteeringAIHandler::PostInit() {
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    if ( !m_pSeekPursueEntityHandler && wxEmptyString != m_SeekPursueEntityHandlerName ) {
        m_pSeekPursueEntityHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_SeekPursueEntityHandlerName ) );
        if ( m_pSeekPursueEntityHandler ) {
            pSteeringAI->SetSeekPursueEntity( static_cast<smeg::core::BaseEntity*>( m_pSeekPursueEntityHandler->GetObject() ) );
        }
    }
    if ( !m_pFleeEvadeEntityHandler && wxEmptyString != m_FleeEvadeEntityHandlerName ) {
        m_pFleeEvadeEntityHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( m_FleeEvadeEntityHandlerName ) );
        if ( m_pFleeEvadeEntityHandler ) {
            pSteeringAI->SetFleeEvadeEntity( static_cast<smeg::core::BaseEntity*>( m_pFleeEvadeEntityHandler->GetObject() ) );
        }
    }
}
    
////////////////////////////////////////////////////////////
/// Return the value of a property
////////////////////////////////////////////////////////////
wxString TestSteeringAIHandler::GetValueAsString( const wxString& _PropertyName ) const {
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    if ( "Seek Weight" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetSeekWeight() );
    } else if ( "Pursue Weight" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetPursueWeight() );
    } else if ( "Flee Weight" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetFleeWeight() );
    } else if ( "Evade Weight" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetEvadeWeight() );
    } else if ( "Wander Weight" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetWanderWeight() );
    } else if ( "Seek Slowing Radius" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetSeekSlowingDistance() );
    } else if ( "Wander Distance" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetWanderDistance() );
    } else if ( "Wander Radius" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetWanderRadius() );
    } else if ( "Max Steering Force" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetSteeringManager()->GetMaxSteeringForce() );
    } else if ( "Seek Pursue Entity" == _PropertyName ) {
        return m_SeekPursueEntityHandlerName;
    } else if ( "Flee Evade Entity" == _PropertyName ) {
        return m_FleeEvadeEntityHandlerName;
    } else if ( "Next Step Threshold" == _PropertyName ) {
        return wxString::Format( "%f", pSteeringAI->GetNextStepThreshold() );
    } else {
        return BaseEntityHandler::GetValueAsString( _PropertyName );
    }
}

////////////////////////////////////////////////////////////
/// Handle the change of a property and apply it to the object
////////////////////////////////////////////////////////////
bool TestSteeringAIHandler::OnPropertyChanged( wxPropertyGrid* _pPropertyGrid, wxPGProperty* _pChangedProperty ) {
    const wxString& propName(_pChangedProperty->GetName());
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    if ( "Seek Weight" == propName ) {
        pSteeringAI->SetSeekWeight( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Pursue Weight" == propName ) {
        pSteeringAI->SetPursueWeight( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Flee Weight" == propName ) {
        pSteeringAI->SetFleeWeight( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Evade Weight" == propName ) {
        pSteeringAI->SetEvadeWeight( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Wander Weight" == propName ) {
        pSteeringAI->SetWanderWeight( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Seek Slowing Radius" == propName ) {
        pSteeringAI->SetSeekSlowingRadius( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Wander Distance" == propName ) {
        pSteeringAI->SetWanderDistance( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Wander Radius" == propName ) {
        pSteeringAI->SetWanderRadius( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Max Steering Force" == propName ) {
        pSteeringAI->GetSteeringManager()->SetMaxSteeringForce( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else if ( "Seek Pursue Entity" == propName ) {
        BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( _pChangedProperty->GetValue().GetString() ) );
        if ( pNewHandler ) {
            m_SeekPursueEntityHandlerName = _pChangedProperty->GetValue().GetString();
            m_pSeekPursueEntityHandler = pNewHandler;
            pSteeringAI->SetSeekPursueEntity( static_cast<smeg::core::BaseEntity*>( m_pSeekPursueEntityHandler->GetObject() ) );
        }
        return true;
    } else if ( "Flee Evade Entity" == propName ) {
        BaseEntityHandler* pNewHandler = dynamic_cast<BaseEntityHandler*>( ((SmegEditorFrame*)m_pCanvas->GetParent())->GetHandlerByName( _pChangedProperty->GetValue().GetString() ) );
        if ( pNewHandler ) {
            m_FleeEvadeEntityHandlerName = _pChangedProperty->GetValue().GetString();
            m_pFleeEvadeEntityHandler = pNewHandler;
            pSteeringAI->SetFleeEvadeEntity( static_cast<smeg::core::BaseEntity*>( m_pFleeEvadeEntityHandler->GetObject() ) );
        }
        return true;
    } else if ( "Path Follow" == propName ) {
        int iPathType = _pChangedProperty->GetValue().GetAny().As<int>();
        if ( 0 == iPathType ) {
            pSteeringAI->ClearFollowPath();
        } else {
            pSteeringAI->FollowPath( m_TmpPath, (smeg::ai::AIEntity::ePathType)(--iPathType) );
        }
        return true;
    } else if ( "Next Step Threshold" == propName ) {
        pSteeringAI->SetNextStepThreshold( _pChangedProperty->GetValue().GetAny().As<float>() );
        return true;
    } else {
        return BaseEntityHandler::OnPropertyChanged( _pPropertyGrid, _pChangedProperty );
    }
}
    
////////////////////////////////////////////////////////////
/// Handle the double click on a property
////////////////////////////////////////////////////////////
bool TestSteeringAIHandler::OnPropertyDoubleClick( wxPropertyGrid* _pPropertyGrid, wxPGProperty* _pChangedProperty ) {
    const wxString& propName(_pChangedProperty->GetName());
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    if ( "Seek Pursue Entity" == propName ) {
        wxArrayString arrayStr;
        arrayStr.Add( m_ID );

        BaseEntityChooserDialog* dlg = new BaseEntityChooserDialog( m_pCanvas->GetParent(), arrayStr );
        dlg->ShowModal();

        if ( dlg->GetChoosenEntityHandler()  ) {
            m_pSeekPursueEntityHandler = dlg->GetChoosenEntityHandler();
            m_SeekPursueEntityHandlerName = m_pSeekPursueEntityHandler->GetId();

            pSteeringAI->SetSeekPursueEntity( static_cast<smeg::core::BaseEntity*>( dlg->GetChoosenEntityHandler()->GetObject() ) );

            _pChangedProperty->SetValueFromString( m_SeekPursueEntityHandlerName );
        }
        dlg->Destroy();

        return true;
    } else if ( "Flee Evade Entity" == propName ) {
        wxArrayString arrayStr;
        arrayStr.Add( m_ID );

        BaseEntityChooserDialog* dlg = new BaseEntityChooserDialog( m_pCanvas->GetParent(), arrayStr );
        dlg->ShowModal();

        if ( dlg->GetChoosenEntityHandler()  ) {
            m_pFleeEvadeEntityHandler = dlg->GetChoosenEntityHandler();
            m_FleeEvadeEntityHandlerName = m_pFleeEvadeEntityHandler->GetId();

            pSteeringAI->SetFleeEvadeEntity( static_cast<smeg::core::BaseEntity*>( dlg->GetChoosenEntityHandler()->GetObject() ) );

            _pChangedProperty->SetValueFromString( m_FleeEvadeEntityHandlerName );
        }
        dlg->Destroy();

        return true;
    } else {
        return BaseEntityHandler::OnPropertyDoubleClick( _pPropertyGrid, _pChangedProperty );
    }
}
   
////////////////////////////////////////////////////////////
/// Create an XML string with the value of the object
////////////////////////////////////////////////////////////
wxString TestSteeringAIHandler::InnerXMLString( const wxString& _ProjectPath, const wxString& _Tab ) const {
    smeg::ai::TestSteeringAI* pSteeringAI = static_cast<smeg::ai::TestSteeringAI*>( m_pObject );
    wxString returnStr = BaseEntityHandler::InnerXMLString( _ProjectPath, _Tab ) +
        _Tab + wxT( "<Param name=\"Next Step Threshold\" value=\"" ) + wxString::Format( "%f", pSteeringAI->GetNextStepThreshold() ) + wxT( "\" />\n" ) +
        _Tab + wxT( "<Param name=\"Max Steering Force\" value=\"" ) + wxString::Format( "%f", pSteeringAI->GetSteeringManager()->GetMaxSteeringForce() ) + wxT( "\" />\n" );
    
    if ( pSteeringAI->GetSeekWeight() > 0.0f ) {
        returnStr += _Tab + wxT( "<Param name=\"Seek Weight\" weight=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekWeight() ) + wxT( "\" " ) 
            + wxT( "target=\"" ) + m_SeekPursueEntityHandlerName + wxT( "\" " ) 
            + wxT( "slowing=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekSlowingDistance() ) + wxT( "\" " ) 
            + wxT( "/>\n" );
    }
    if ( pSteeringAI->GetPursueWeight() > 0.0f ) {
        returnStr += _Tab + wxT( "<Param name=\"Pursue Weight\" weight=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekWeight() ) + wxT( "\" " ) 
            + wxT( "target=\"" ) + m_SeekPursueEntityHandlerName + wxT( "\" " ) 
            + wxT( "/>\n" );
    }
    if ( pSteeringAI->GetFleeWeight() > 0.0f ) {
        returnStr += _Tab + wxT( "<Param name=\"Flee Weight\" weight=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekWeight() ) + wxT( "\" " ) 
            + wxT( "target=\"" ) + m_FleeEvadeEntityHandlerName + wxT( "\" " ) 
            + wxT( "/>\n" );
    }
    if ( pSteeringAI->GetEvadeWeight() > 0.0f ) {
        returnStr += _Tab + wxT( "<Param name=\"Evade Weight\" weight=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekWeight() ) + wxT( "\" " ) 
            + wxT( "target=\"" ) + m_FleeEvadeEntityHandlerName + wxT( "\" " ) 
            + wxT( "/>\n" );
    }
    if ( pSteeringAI->GetWanderWeight() > 0.0f ) {
        returnStr += _Tab + wxT( "<Param name=\"Wander Weight\" weight=\"" ) + wxString::Format( "%f", pSteeringAI->GetSeekWeight() ) + wxT( "\" " ) 
            + wxT( "distance=\"" ) + wxString::Format( "%f", pSteeringAI->GetWanderDistance() ) + wxT( "\" " ) 
            + wxT( "radius=\"" ) + wxString::Format( "%f", pSteeringAI->GetWanderRadius() ) + wxT( "\" " ) 
            + wxT( "/>\n" );
    }

    return returnStr;
}